package basis.reflective;

import basis.第十四章.Example;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class Demo1 {


    public static void main(String[] args) {

        try {
            //获取Class对象1
            Class<?> exampleClass = Class.forName("basis.第十四章.Example");
            //获取Class对象2
            Example example = new Example();
            Class<?> exampleClass2 = example.getClass();
            //获取Class对象3
            Class<Example> exampleClass3 = Example.class;
            //获取Class对象4
            Class<Integer> integerClass = int.class;

            Example example2 = (Example)exampleClass.newInstance();
            example.you();
            Field[] fields = exampleClass.getFields();
            Method[] methods = exampleClass.getMethods();
            Constructor<?>[] constructors = exampleClass.getConstructors();
            for(Constructor constructor:constructors){
                System.out.println(constructor);
            }
            for(Method m :methods){
                System.out.println(m);

            }
            for(Field f :fields){
                System.out.println(f);
            }



        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }catch (InstantiationException e2){
            e2.printStackTrace();
        }catch (IllegalAccessException e3){
            e3.printStackTrace();
        }
    }
}
